package com.project.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class BaseDao {
    protected Connection con;
    protected PreparedStatement ps;
    protected ResultSet rs;
    public void setConnection(){
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:6789/db?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false",
                    "root","lovo");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void closeConection(){
        try{
            if(rs != null){
                rs.close();
            }
            if(ps != null){
                ps.close();
            }
            if(con != null){
                con.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        BaseDao dao = new BaseDao();
        dao.setConnection();
        System.out.println(dao.con);
    }
}
